package org.ceteca.explica.client.partners;

import org.ceteca.explica.client.gui.common.CommonClient;
import org.ceteca.explica.core.common.BaseVO;
import org.ceteca.explica.core.partners.ContactOT;
import org.ceteca.explica.core.partners.InterfacePartners;
import org.ceteca.explica.core.partners.PartnerGroupOT;
import org.ceteca.explica.core.util.Converter;
import org.ceteca.explica.core.util.OperationResult;
import org.eclipse.swt.widgets.Text;


/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class PartnerGroupClient extends CommonClient {

	private Text entryCode, entryName;
	
	
	public PartnerGroupClient() {
		super(PartnerGroupOT.class, InterfacePartners.EXPLICA_EDIT_PARTNERGROUP_GLADE_PATH,InterfacePartners.EXPLICA_EDIT_PARTNERGROUP_DIALOG_NAME);
	}



	@Override
	public BaseVO getEntityData() {
		PartnerGroupOT dep=new PartnerGroupOT();
		if (this.entEditView!=null){
			dep.setDescription( entryName.getText());
		}
		if (selectedEntity!=null){
			dep.setVersion(((PartnerGroupOT)this.selectedEntity).getVersion());
			dep.setIdPartnerGroup(((PartnerGroupOT)this.selectedEntity).getIdPartnerGroup());
		}
		return dep;
	}





	@Override
	public OperationResult validateEntity() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setWidgetsValues(BaseVO entity) {
		PartnerGroupOT pg = (PartnerGroupOT)entity;
		entryCode.setText(Converter.getInstance().toString(pg.getIdPartnerGroup()));
		entryName.setText(Converter.getInstance().toString(pg.getDescription()));
		
	}

	@Override
	public void getWidgets() {
	
		int allOk = 0;
		// Entries
		entryCode = (Text) this.getWidget(
				InterfacePartners.EDIT_PARTNERGROUP_CODE_WIDGETNAME);
		if (entryCode == null)
			allOk = 1;
		entryName = (Text) this.getWidget(
				InterfacePartners.EDIT_PARTNERGROUP_DESCRIPTION_WIDGETNAME);
		if (entryName == null)
			allOk = 2;
		
		if (allOk != 0) {
			// this.logger.fatal("Error getting widgets");
			this.logger.debug("Error getting widget #" + allOk);
			fireExceptionAndExit("Error obtentiendo widgets");
		}
	}

	@Override
	public void buildSelectionSets() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void setEditionMode(boolean enabled) {
		this.getWidgets();
		entryCode.setEnabled(false);
		entryName.setEnabled(enabled);
		
	}

	@Override
	public void init_specific_components() {
		// TODO Auto-generated method stub
		
	}



	@Override
	public void build_extension_fields_view() {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void fillEntityData() {
		if (this.selectedEntity != null && this.entEditView != null) {
			getWidgets();
			setWidgetsValues((PartnerGroupOT) selectedEntity);
		}
	}

}
